import javax.swing.*;
import java.awt.*;
import java.util.ArrayList;
import java.util.List;
import java.util.Map;

public class Draw {

    public static final int WIDTH = 600;
    public static final int LENGTH = 600;
    public static final int RIM = 100;//边框
    public static final int RADIUS = 2;

    JFrame frame = new JFrame();
    List<Point> points;
//    List<Point> shell;
    List<Triangle> triangles;
//    Map<Point, ArrayList<Point>> vor;

    class myCanvas extends Canvas {
        @Override
        public void paint(Graphics g) {
            g.setColor(Color.BLUE);
            if (triangles != null)
                for (Triangle tri: triangles){
                    g.drawLine(transX(tri.a.x)+ RIM / 2,transY(tri.a.y)+ RIM / 2,transX(tri.b.x)+ RIM / 2,transY(tri.b.y)+ RIM / 2);
                    g.drawLine(transX(tri.a.x)+ RIM / 2,transY(tri.a.y)+ RIM / 2,transX(tri.p.x)+ RIM / 2,transY(tri.p.y)+ RIM / 2);
                    g.drawLine(transX(tri.b.x)+ RIM / 2,transY(tri.b.y)+ RIM / 2,transX(tri.p.x)+ RIM / 2,transY(tri.p.y)+ RIM / 2);
                }
            g.setColor(Color.RED);
            if (points != null)
                for (Point point:points)
                    g.fillOval(transX(point.x) + RIM / 2 - RADIUS, transY(point.y) + RIM / 2 - RADIUS, RADIUS * 2, RADIUS * 2);
/*
            g.setColor(Color.BLACK);
            if (shell != null)
                for (Point point:shell)
                    g.fillOval(transX(point.x) + RIM / 2 - RADIUS, transY(point.y) + RIM / 2 - RADIUS, RADIUS * 2, RADIUS * 2);


            g.setColor(Color.GREEN);
            if(vor != null)
                for (Point point:points){
                    int count = vor.get(point).size();
                    if(count>2)
                        for(int i = 0;i<count;++i){
                            if(i < count-1)
                                g.drawLine(transX(vor.get(point).get(i).x)+ RIM / 2,transY(vor.get(point).get(i).y)+ RIM / 2,transX(vor.get(point).get(i+1).x)+ RIM / 2,transY(vor.get(point).get(i+1).y)+ RIM / 2);
                            else
                                g.drawLine(transX(vor.get(point).get(i).x)+ RIM / 2,transY(vor.get(point).get(i).y)+ RIM / 2,transX(vor.get(point).get(0).x)+ RIM / 2,transY(vor.get(point).get(0).y)+ RIM / 2);
                        }
                }
*/
        }
    }


    private int transX(double x){
        return (int)(WIDTH / 100.0 * x);
    }
    private int transY(double y){
        return (int)(LENGTH / 100.0 * y);
    }

    public void draw(List<Point> points,List<Triangle> tris){
        this.points = points;
        this.triangles = tris;

        myCanvas drawArea = new myCanvas();
        drawArea.setSize(WIDTH+RIM,LENGTH+RIM);
        frame.add(drawArea);

        frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
        frame.pack();
        frame.setVisible(true);
    }
}